#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2021 wanghch <wanghch@wanghch-pc>
#
# Distributed under terms of the MIT license.

"""

"""
import pandas as pd
# from sklearn.model_selection import train_test_split
import tensorflow as tf
import os
import sys
from tensorflow.keras.layers import *

from feature_utils import *


import argparse
import datetime

today = datetime.datetime.today()
parser = argparse.ArgumentParser(description='job args')
parser.add_argument('-m', '--model', type=str, default="model", help='model dir')

ARGS = parser.parse_args()





def get_dataset():
    dfiles = os.listdir('export/')
    absfiles = ["export/" + f for f in dfiles]
    dfs = []
    for af in absfiles:
        df = pd.read_csv(af, names = INF_COLUMNS, header = None)
        dfs.append(df)
    df = pd.concat(dfs)
    df['dt'] = pd.to_datetime(df.date)
    return df



def gen_input(X):
    # X_num_fea = X.loc[:, FNAMES]
    x_map = {n: X.loc[:, n] for n in CAT_FNAMES + FNAMES}
    # x_map["X"] = X_num_fea
    return x_map



df = get_dataset()

N_NUM_FEATURES = len(FNAMES)
N_CAT_FEATURES = len(CAT_FNAMES)


model_dir = ARGS.model
X_map = gen_input(df)

model = tf.keras.models.load_model(model_dir)
df["Y"] = model.predict(X_map)

export_columns = ["date", "name", "code", "Y"]
df[export_columns].to_csv("/tmp/predict.csv", index = False)
